#include "cardpanel.h"

#include <QMouseEvent>
#include <QPainter>

CardPanel::CardPanel(QWidget *parent) : QWidget(parent) { }

// 设置和获取图片
void CardPanel::setImage(const QPixmap &front, const QPixmap &back){
    m_front = front;
    m_back = back;

    setFixedSize(m_front.size());

    update();
}
QPixmap CardPanel::getImage(){
    return m_front;
}

//
void CardPanel::setFrontSide(bool flag){
    m_isfront = flag;
}
bool CardPanel::isFrontSide(){
    return m_isfront;
}

// 设置选择状态和获取选择状态
void CardPanel::setSeclected(bool flag){
    m_isSelect = flag;
}
bool CardPanel::isSelected(){
    return m_isSelect;
}

// 设置拍片和获取卡片
void CardPanel::setCard(const Card &card){
    m_card = card;
}
Card CardPanel::getCard(){
    return m_card;
}

// 设置卡牌的拥有者和获取卡牌的拥有者
void CardPanel::setOwner(Player *player){
    m_owner = player;
}
Player *CardPanel::getOwner(){
    return m_owner;
}

// 点击卡牌
void CardPanel::clicked(){
    emit cardSelected(Qt::LeftButton);
}

void CardPanel::paintEvent(QPaintEvent *event){
    Q_UNUSED(event)
    QPainter p(this);
    if(m_isfront)
        p.drawPixmap(rect(), m_front);
    else
        p.drawPixmap(rect(), m_back);
}

void CardPanel::mousePressEvent(QMouseEvent *event){
    emit cardSelected(event->button());
}
